<?php
if ( ! defined( 'NV_IS_VIDEO_ADMIN' ) ) { die( 'Stop!!!' ); }
$page_title = "Quản lí thể loại";
$contents="";
$sql = "SELECT id, num,  title FROM `" . NV_PREFIXLANG . "_" . $module_data . "_category`";
$resuilt = $db->sql_query( $sql );
$num=1;
while ( $row = $db->sql_fetchrow( $resuilt ) )
{
	$num++;
}
///////////////////////////////////THÊM THẺ LOẠI/////////////////////////////////////
$add = 0; 
$error = ""; 
if ( $nv_Request->get_int( 'add', 'post' ) == 1 ) 
{ 
	$title = filter_text_input( 'title', 'post', '', 1 ); 
	if ( empty( $title ) ) { $error = "Lỗi: Chưa điền đủ thông tin."; }
	else 
	{ 
		$query = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_category` (`id`, `num`, `title`) VALUES ( NULL, ".$num.", " . $db->dbescape( $title ) . ")"; 
		if ( $db->sql_query_insert_id( $query ) ) 
		{ 
			$db->sql_freeresult(); 
			Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=video&" . NV_OP_VARIABLE . "=category" ); die(); 
		} 
		else { $error = "Có lỗi trong quá trình lưu dữ liệu hãy kiểm tra lại"; } 
	} 
} 
if ( $error != "" ) 
{ 
	$contents .= "<div class=\"quote\" style=\"width:780px;\">\n"; 
	$contents .= "<blockquote class=\"error\"><span>" . $error . "</span></blockquote>\n"; 
	$contents .= "</div>\n"; 
	$contents .= "<div class=\"clear\"></div>\n"; 
} 
$contents .= "<br /><strong>Thêm thể loại<br /></strong>";
$contents .= "<form action=\"" . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=video&amp;" . NV_OP_VARIABLE . "=category\" enctype=\"multipart/form-data\" method=\"post\">"; 
$contents .= " 		<input type=\"text\" name=\"title\" size=\"100\">\n"; 
$contents .= " 		<input type=\"submit\" value=\"Thêm\"/>\n"; 
$contents .= " 		<input name=\"add\" type=\"hidden\" value=\"1\" />\n"; 
$contents .= " 		<input type=\"hidden\" name =\"" . NV_NAME_VARIABLE . "\"value=\"" . $module_name . "\" />"; $contents .= " 		<input type=\"hidden\" name =\"" . NV_OP_VARIABLE . "\"value=\"" . $op . "\" />"; 
$contents .= "</form>\n"; 
/////////////////////////////////////Hiển thị thể loại////////////////////////////////////////
$contents.="
<table class=\"tab1\"> 
<tr style=\"text-align:center;\">
	<td>ID</td>
	<td>Thể loại</td>
	<td>Chức năng</td>
</tr>";
$sql = "SELECT id, num,  title FROM `" . NV_PREFIXLANG . "_" . $module_data . "_category`";
$resuilt = $db->sql_query( $sql );
while ( $row = $db->sql_fetchrow( $resuilt ) )
{
	$contents.="
	<tr>
		<td style=\"text-align:center;\">".$row['id']."</td>
		<td>".$row['title']."</td>
		<td style=\"text-align:center;\"><a href=\"index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=category&del=1&id=" . $row['id'] . "\">Xóa</a></td> 
	</td>";
}
$contents.="</table>";
///////////////////////////////////XÓA THỂ LOẠI //////////////////////////////////
if($nv_Request->get_int( 'del', 'post,get', 0 ))
{
	$id= $nv_Request->get_int( 'id', 'get', 0 );	
    $sql = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_category` WHERE `id`=" . $id;
    $db->sql_query( $sql );
    Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=video&" . NV_OP_VARIABLE . "=category" );
    exit();  
}
include ( NV_ROOTDIR . "/includes/header.php" );
echo nv_admin_theme( $contents );
include ( NV_ROOTDIR . "/includes/footer.php" );
?>